﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RR87Response", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR87Response))]
    public class RR87ResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRR87Response clazz;
        
        public RR87ResponseSerializer(IRR87Response clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Info");
            if (clazz.Info!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Info))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Info");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Veakood");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Veakood))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("Veatekst");
            if (clazz.Veatekst!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Veatekst))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Veatekst");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Isikuandmed");
            if (clazz.Isikuandmed!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute(">>>RR87Response>Isikuandmed>Isikuandmed", "http://producers.rr.xtee.riik.ee/producer/rr", clazz.Isikuandmed.Count);
                for (int x = 0; ((clazz.Isikuandmed != null) 
                            && (x < clazz.Isikuandmed.Count)); x = (x + 1)) {
                    if (clazz.Isikuandmed[x]!=null) {
                        Writer.WriteStartElement("Isikuandmed");
                        global::Xtee.Core.SerializationMetadata metaIsikuandmed = this.GetMetaData(clazz.Isikuandmed[x]);
                        Writer.WriteTypeAttribute(metaIsikuandmed.TypeQualifiedName.Namespace, metaIsikuandmed.TypeQualifiedName.Name);
                        metaIsikuandmed.NewSerializer(clazz.Isikuandmed[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isikuandmed");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Info") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR87Response>Info");
                }
                clazz.Info = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Info")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR87Response>Info", Reader.LocalName);
            }
            if (Reader.LocalName=="Veakood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR87Response>Veakood");
                }
                clazz.Veakood = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("Veakood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR87Response>Veakood", Reader.LocalName);
            }
            if (Reader.LocalName=="Veatekst") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR87Response>Veatekst");
                }
                clazz.Veatekst = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Veatekst")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR87Response>Veatekst", Reader.LocalName);
            }
            if (Reader.LocalName=="Isikuandmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR87Response>Isikuandmed");
                }
                clazz.Isikuandmed = new System.Collections.Generic.List<RR87Response.IIsikuandmedType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("Isikuandmed");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "Isikuandmed")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>RR87Response>Isikuandmed>Isikuandmed");
                        }
                        global::Xtee.Core.SerializationMetadata metaIsikuandmed = this.GetMetaData<RR87Response.IIsikuandmedType>(Reader, ">>>RR87Response>Isikuandmed>Isikuandmed", "http://producers.rr.xtee.riik.ee/producer/rr");
                        RR87Response.IIsikuandmedType item = metaIsikuandmed.NewEntity<RR87Response.IIsikuandmedType>();
                        clazz.Isikuandmed.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("Isikuandmed");
                            metaIsikuandmed.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR87Response>Isikuandmed", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>RR87Response>Isikuandmed>Isikuandmed", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR87Response.IsikuandmedType))]
        public class IsikuandmedTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected RR87Response.IIsikuandmedType clazz;
            
            public IsikuandmedTypeSerializer(RR87Response.IIsikuandmedType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("Isikuandmed.Isikukood");
                if (clazz.IsikuandmedIsikukood!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikuandmedIsikukood))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuandmedIsikukood");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikuandmed.Eesnimi");
                if (clazz.IsikuandmedEesnimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikuandmedEesnimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuandmedEesnimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikuandmed.Perenimi");
                if (clazz.IsikuandmedPerenimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikuandmedPerenimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuandmedPerenimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikuandmed.IsikuStaatus");
                if (clazz.IsikuandmedIsikuStaatus!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikuandmedIsikuStaatus))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuandmedIsikuStaatus");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikuandmed.Surmaaeg");
                if (clazz.IsikuandmedSurmaaeg!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikuandmedSurmaaeg))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuandmedSurmaaeg");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikuandmed.Kodakondsuskood");
                if (clazz.IsikuandmedKodakondsuskood!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikuandmedKodakondsuskood))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuandmedKodakondsuskood");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikuandmed.Kodakondsustekstina");
                if (clazz.IsikuandmedKodakondsustekstina!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikuandmedKodakondsustekstina))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuandmedKodakondsustekstina");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikuandmed.EKodakondsuskood");
                if (clazz.IsikuandmedEKodakondsuskood!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikuandmedEKodakondsuskood))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuandmedEKodakondsuskood");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikuandmed.EKodakondsustekstina");
                if (clazz.IsikuandmedEKodakondsustekstina!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikuandmedEKodakondsustekstina))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuandmedEKodakondsustekstina");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikuandmed.AadressTekstina");
                if (clazz.IsikuandmedAadressTekstina!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikuandmedAadressTekstina))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuandmedAadressTekstina");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikuandmed.Sideaadress");
                if (clazz.IsikuandmedSideaadress!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikuandmedSideaadress))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikuandmedSideaadress");
                }
                Writer.WriteEndElement();
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="Isikuandmed.Isikukood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.Isikukood");
                    }
                    clazz.IsikuandmedIsikukood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikuandmed.Isikukood")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.Isikukood", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikuandmed.Eesnimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.Eesnimi");
                    }
                    clazz.IsikuandmedEesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikuandmed.Eesnimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.Eesnimi", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikuandmed.Perenimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.Perenimi");
                    }
                    clazz.IsikuandmedPerenimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikuandmed.Perenimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.Perenimi", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikuandmed.IsikuStaatus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.IsikuStaatus");
                    }
                    clazz.IsikuandmedIsikuStaatus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikuandmed.IsikuStaatus")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.IsikuStaatus", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikuandmed.Surmaaeg") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.Surmaaeg");
                    }
                    clazz.IsikuandmedSurmaaeg = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikuandmed.Surmaaeg")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.Surmaaeg", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikuandmed.Kodakondsuskood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.Kodakondsuskood");
                    }
                    clazz.IsikuandmedKodakondsuskood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikuandmed.Kodakondsuskood")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.Kodakondsuskood", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikuandmed.Kodakondsustekstina") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.Kodakondsustekstina");
                    }
                    clazz.IsikuandmedKodakondsustekstina = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikuandmed.Kodakondsustekstina")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.Kodakondsustekstina", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikuandmed.EKodakondsuskood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.EKodakondsuskood");
                    }
                    clazz.IsikuandmedEKodakondsuskood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikuandmed.EKodakondsuskood")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.EKodakondsuskood", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikuandmed.EKodakondsustekstina") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.EKodakondsustekstina");
                    }
                    clazz.IsikuandmedEKodakondsustekstina = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikuandmed.EKodakondsustekstina")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.EKodakondsustekstina", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikuandmed.AadressTekstina") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.AadressTekstina");
                    }
                    clazz.IsikuandmedAadressTekstina = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikuandmed.AadressTekstina")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.AadressTekstina", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikuandmed.Sideaadress") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.Sideaadress");
                    }
                    clazz.IsikuandmedSideaadress = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikuandmed.Sideaadress")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR87Response>Isikuandmed>Isikuandmed>Isikuandmed.Sideaadress", Reader.LocalName);
                }
            }
        }
    }
}
